Skip to content

Fix output routing when threads inherit context - #1559

Open
emecii wants to merge 1 commit into
ipython:mainfrom
emecii:fix/thread-inherited-parent-header
Open

Fix output routing when threads inherit context#1559
emecii wants to merge 1 commit into
ipython:mainfrom
emecii:fix/thread-inherited-parent-header

Conversation

@emecii

@emecii emecii commented Sep 10, 2026

Copy link
Copy Markdown

Closes #1491

A background thread can inherit the executing cell's ContextVar state (the default on free-threaded CPython, and also possible with copy_context). Because ipykernel treated any context-local parent as belonging to the current thread, a persistent worker stayed pinned to the cell that created it.

Store the setting thread ID with each context-local parent, and fall back to the current global parent when another thread observes an inherited context. Explicit set_parent and set_thread_parent calls in the worker still pin output as before.

The regression runs a worker in a copied context and covers both stream and display output across three cells, including explicit global and temporary thread-local overrides.

🤖🤖 AI-assisted contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log messages written from a helper thread appear in the wrong notebook cell (regression)

1 participant